#include "ObjectOutputStream.h"

namespace Entities {

ObjectOutputStream::ObjectOutputStream( ostream & _out) : out(_out) {}

ObjectOutputStream & ObjectOutputStream::operator<<(ostream & (*f)(ostream & )){
	out << *f;
	return *this;
}

ostream & operator<<(ostream & os, const ObjectOutputStream & obj){
	return obj.out;
}

ostream & ObjectOutputStream::getStream(){
	return out;
}

ObjectOutputStream & ObjectOutputStream::operator<<(const Serializable & obj){
	Serializable * s = const_cast<Serializable *>(&obj);
	Typable * t = dynamic_cast<Typable *>(s);
	if (t) writeObject(obj, t->getType());
	else writeObject(obj);
	return *this;
}

ObjectOutputStream & ObjectOutputStream::operator<<(ObjectOutputStream & (*f)(ObjectOutputStream & )){
	return (*f)(*this);
}

}